package com.mes.handler;

import java.util.Map;
import org.codehaus.jettison.json.JSONObject;
import org.openbravo.client.kernel.BaseActionHandler;
import org.openbravo.dal.service.OBDal;

//作业订单查看工序绑定的工艺标准
public class ViewDrawingsOrderHandler extends BaseActionHandler {
	@Override
	protected JSONObject execute(Map<String, Object> parameters, String data) {
		JSONObject jsonRep = new JSONObject();
		try {
			jsonRep.put("flag", true);
			JSONObject jsonData = new JSONObject(data);
			String resultId = jsonData.getString("id");
			String processId = jsonData.getString("processId");
			String name = jsonData.getString("routeNo");
			String sql = null;
			if (processId != null && !"".equals(processId)) {
				sql = "select picturepath from Emes_Process where Emes_Process = '" + processId + "'";
			} else {
				sql = "select picturepath from Emes_Process " + "where Emes_Process_Route_id =("
						+ "select mo.Emes_Process_Route_ID from Emeso_ManuOrder mo"
						+ "  where Emeso_ManuOrder_id = (select Emeso_ManuOrder_id from"
						+ " Emeso_ManuOrder_Job_Order  where code = '" + resultId + "')) " + "  and route_no = '"
						+ name + "'";
			}
			String result = (String) OBDal.getInstance().getSession().createSQLQuery(sql).uniqueResult();
			if (result == null) {
				jsonRep.put("message", "该工序没有上传工艺标准！！");
				jsonRep.put("flag", false);
			} else {
				jsonRep.put("meg", result);
				jsonRep.put("flag", true);
			}
			OBDal.getInstance().commitAndClose();
		} catch (Exception e) {
			OBDal.getInstance().rollbackAndClose();
			e.printStackTrace();
		}
		return jsonRep;
	}
}
